﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

using System.IO.IsolatedStorage;
using Microsoft.Phone.Marketplace;
namespace SkyReader
{
    public partial class Bookmarks : PhoneApplicationPage
    {
        private Book book;
        public Bookmarks()
        {
            InitializeComponent();

            Deployment.Current.Dispatcher.BeginInvoke(BindBookmarkList);
            //BindBookmarkList();
        }

        private void BindBookmarkList()
        {
            IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
            string fileName = settings["VARIABLE_CURRENTFILENAME"].ToString();

            foreach (var setting in settings)
            {
                if (setting.Value is Book)
                {
                    book = setting.Value as Book;
                    if (book.FileName == fileName)
                    {
                        break;
                    }
                }
            }

            lstBookMark.ItemsSource = book.MarkList;

            settings[book.Id] = book;
            settings.Save();

            this.LoadPanel.Visibility = System.Windows.Visibility.Collapsed;
            this.ContentPanel.Visibility = System.Windows.Visibility.Visible;
        }

        private void ButtonGotoBookmark_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;
            int pageIndex = int.Parse(btn.Tag.ToString());
            this.book.CurrentPage = pageIndex;

            NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
        }
    }
}